/**
 * 文件名：MtvruleServiceImpl.java
 *
 * 版本信息：
 * 日期：Sep 19, 2009
 * Copyright dp Corporation 2009 
 * 版权所有 2009All rights reserved.
 * 创建者：
 *
 */
package com.dp.service.impl3;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.dp.pojo.JsonPage;
import com.dp.service.impl3.BaseImpl;
import com.dp.vo.NewsMtvrule;

@Service
@Transactional
public class MtvruleServiceImpl3 extends BaseImpl{
	   
	/**
	 * 查询
	 * @param clientua
	 * @return
	 */
	public Long findMtvruleCount(String clientua,JsonPage jpage) 
	{
		StringBuffer hql = new StringBuffer("SELECT count(a) FROM NewsMtvrule a where 1=1 ");
		if (clientua != null && !"".equals(clientua)) {
			hql.append(" and a.clientua like '%" + clientua + "%'");
		}
		if(jpage!=null){
			if(jpage.getSidx()!=null&&!"".equals(jpage.getSidx())){
				hql.append(" order by a."+jpage.getSidx());
				hql.append(" "+jpage.getSord());
			}
		}
		Object obj = getSingleResult(hql.toString());
		if(obj ==null ){
			return 0L;
		}else{
			return (Long) obj;
		}
	}
	
	/**
	 * 查询,分页
	 * @param clientua
	 * @return
	 */
	public List<NewsMtvrule> findMtvrule(String clientua,JsonPage jpage,int firstrow, int maxrow) 
	{
		StringBuffer hql = new StringBuffer("SELECT a FROM NewsMtvrule a where 1=1 ");
		if (clientua != null && !"".equals(clientua)) {
			hql.append(" and a.clientua like '%" + clientua + "%'");
		}	
		if(jpage!=null){
			if(jpage.getSidx()!=null&&!"".equals(jpage.getSidx())){
				hql.append(" order by a."+jpage.getSidx());
				hql.append(" "+jpage.getSord());
			}
		}
		return getQueryList(hql.toString(), firstrow, maxrow);
	}
	
	/*public NewsMtvrule findAdById(String clientua1)
	{
		String hql = "SELECT a FROM NewsMtvrule a where 1=1 ";
		if (clientua1 != null && !"".equals(clientua1)) {
			hql += " and a.clientua = '" + clientua1 +"'";
		}
		return (NewsMtvrule)getSingleResult(hql);
	}*/
	
	public int update(NewsMtvrule mtvrule,String clientua_old) {		
		String hql="UPDATE NewsMtvrule SET clientua='"+mtvrule.getClientua()+"',musicformat='"+mtvrule.getMusicformat()+"',videoformat='"+mtvrule.getVideoformat()+"',imageformat='"+mtvrule.getImageformat()+"' where 1=1 and clientua='"+clientua_old+"'"; 
		return super.updateHql(hql);
	}
	
	public int checkClientua(String clientua,String old_clientua) {
		String hql = "SELECT a FROM NewsMtvrule a where 1=1 ";
		if (clientua!= null && !"".equals(clientua)) {
			hql += " and a.clientua = '" + clientua +"'";
		}
		if (old_clientua!= null && !"".equals(old_clientua)) {
			hql += " and a.clientua != '" + old_clientua +"'";
		}
		System.out.println("hql:"+hql);
		return getSingleResult(hql)==null ? 0 :1;
	}
	
	public NewsMtvrule checkMtvrule_clientua(String clientua) {
		String hql = "SELECT a FROM NewsMtvrule a where 1=1 ";
		if (clientua!= null && !"".equals(clientua)) {
			hql += " and a.clientua = '" + clientua +"'";
		}
		return (NewsMtvrule)getSingleResult(hql);
	}

	/**
	 * Delete NewsBlacklist Entity
	 * @param urlB
	 * @return boolean b
	 */
	public boolean deleteNewsMtvruleByClientUA(String clientua) {
		String jpql="DELETE NewsMtvrule n WHERE n.clientua='"+clientua+"'";
		return super.updateHql(jpql)>0;
	}
}
